from django.db import models

from Problems.models import ProblemTag


class RemoteProblem(models.Model):
    name = models.CharField(max_length=100, null=False, blank=False, verbose_name="题目名称")
    remote_oj = models.ForeignKey('Robots.RemoteOJ', on_delete=models.PROTECT, related_name="problems_in_admin",
                                  verbose_name="题目来源")
    rating = models.IntegerField(default=0 , blank=True, verbose_name="题目难度")
    remote_id = models.CharField(unique=True, max_length=100, null=False, blank=False, verbose_name="远程ID")
    remote_url = models.CharField(max_length=100, null=False, blank=False, verbose_name="题目链接")
    tags = models.ManyToManyField(ProblemTag, blank=True, verbose_name="题目标签")
    solvedCount = models.IntegerField(verbose_name="通过人数")
    is_get_problem_success = models.BooleanField(default=False, verbose_name="获取问题状态")
    totalSubmissions = models.IntegerField(verbose_name="提交人数" , blank=True, null=True)

    # 使用property装饰器实现的属性，用于检查是否成功获取问题。

    def __str__(self):
        return f"{self.remote_oj.name}-{self.remote_id}"

    class Meta:
        ordering = ["id"]
